//
//  HBMyRedPacketListCell.m
//  HuoBao
//
//  Created by chaiyanan on 15/12/7.
//  Copyright © 2015年 jinxin. All rights reserved.
//

#import "HBMyRedPacketListCell.h"

@implementation HBMyRedPacketListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
//        self.backgroundColor = [LCCommon getColor:@"37383d"];
        self.backgroundColor = [UIColor clearColor];
        
        [self createCustomView];
    }
    return self;
}

- (void)createCustomView
{
    //86*102
    UIImage *redImage = [UIImage imageNamed:@"My_RedPacket"];
    self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(15, 16, 86/2.0, 102/2.0)];
    self.headImageView.image = redImage;
    [self.contentView addSubview:self.headImageView];
    
    self.titleLable = [self createLableWithTextColor:[LCCommon getColor:@"b1b1b1"] font:[UIFont systemFontOfSize:16.0f] text:@"加息红包" textAlignment:NSTextAlignmentLeft frame:CGRectMake(self.headImageView.x+self.headImageView.width+21, 16, SCREEN_WIDTH-(self.headImageView.x+self.headImageView.width+21+15), 16.0f) superView:self.contentView];
    
    UILabel *fromTitleLable = [self createLableWithTextColor:[LCCommon getColor:@"888888"] font:[UIFont systemFontOfSize:11.0f] text:@"来自：" textAlignment:NSTextAlignmentLeft frame:CGRectMake(self.headImageView.x+self.headImageView.width+21, self.titleLable.y+self.titleLable.height+8, 60, 11.0f) superView:self.contentView];
    [fromTitleLable sizeToFit];
    CGRect lableFrame = fromTitleLable.frame;
    lableFrame.origin = CGPointMake(self.headImageView.x+self.headImageView.width+21, self.titleLable.y+self.titleLable.height+8);
    lableFrame.size.height = 11.0f;
    fromTitleLable.frame = lableFrame;
    
    self.fromLable = [self createLableWithTextColor:[LCCommon getColor:@"b1b1b1"] font:[UIFont systemFontOfSize:11.0f] text:@"摇一摇" textAlignment:NSTextAlignmentLeft frame:CGRectMake(fromTitleLable.x+fromTitleLable.width+5, fromTitleLable.y, SCREEN_WIDTH-(fromTitleLable.x+fromTitleLable.width+10+60), 11.0f) superView:self.contentView];
    
    UILabel *timeTitleLable = [self createLableWithTextColor:[LCCommon getColor:@"888888"] font:[UIFont systemFontOfSize:11.0f] text:@"有效时间：" textAlignment:NSTextAlignmentLeft frame:CGRectMake(self.headImageView.x+self.headImageView.width+21, fromTitleLable.y+fromTitleLable.height+8, 60, 11.0f) superView:self.contentView];
    [timeTitleLable sizeToFit];
    lableFrame = timeTitleLable.frame;
    lableFrame.origin = CGPointMake(self.headImageView.x+self.headImageView.width+21, fromTitleLable.y+fromTitleLable.height+8);
    lableFrame.size.height = 11.0f;
    timeTitleLable.frame = lableFrame;
    
    self.timeLable = [self createLableWithTextColor:[LCCommon getColor:@"b1b1b1"] font:[UIFont systemFontOfSize:11.0f] text:@"2015-12-20" textAlignment:NSTextAlignmentLeft frame:CGRectMake(timeTitleLable.x+timeTitleLable.width+5, timeTitleLable.y, SCREEN_WIDTH-(timeTitleLable.x+timeTitleLable.width+10+15), 11.0f) superView:self.contentView];
    
    //cccccc
    [self createSepratorLineWithFrame:CGRectMake(15, Height_HBMyRedPacketListCell-1-1/([UIScreen mainScreen].scale), SCREEN_WIDTH-30, 1/([UIScreen mainScreen].scale)) backgroundColor:[LCCommon getColor:@"37383d"] superView:self.contentView];
    
    self.rateLable = [self createLableWithTextColor:[LCCommon getColor:@"fc353b"] font:[UIFont systemFontOfSize:11.0f] text:@"+0.5%" textAlignment:NSTextAlignmentRight frame:CGRectMake(SCREEN_WIDTH-15-50, 19, 50, 11.0f) superView:self.contentView];
    self.statusLable = [self createLableWithTextColor:[LCCommon getColor:@"db9441"] font:[UIFont systemFontOfSize:11.0f] text:@"生效中" textAlignment:NSTextAlignmentRight frame:CGRectMake(SCREEN_WIDTH-15-50, self.rateLable.y+self.rateLable.height+11, 50, 11.0f) superView:self.contentView];
    
}

- (UILabel *)createLableWithTextColor:(UIColor *)color font:(UIFont *)font text:(NSString *)text textAlignment:(NSTextAlignment)textAlignment frame:(CGRect)frame superView:(UIView *)superView
{
    UILabel *lable = [[UILabel alloc]initWithFrame:frame];
    lable.textColor = color;
    lable.font = font;
    lable.text = text;
    lable.textAlignment = textAlignment;
    [superView addSubview:lable];
    return lable;
}

- (UIView *)createSepratorLineWithFrame:(CGRect)frame backgroundColor:(UIColor *)bgColor superView:(UIView *)superView
{
    UIView *sepratorLine = [[UIView alloc]initWithFrame:frame];
    sepratorLine.backgroundColor = bgColor;
    [superView addSubview:sepratorLine];
    return sepratorLine;
}


@end
